package wisata.ina;
import java.util.ArrayList;
import java.util.List;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
 
public class DatabaseHandler extends SQLiteOpenHelper {
 
    // All Static variables
    // Database Version
    private static final int DATABASE_VERSION = 1;
 
    // Database Name
    private static final String DATABASE_NAME = "pn_15531166_tugasakhir";
 
    // Login table name
    private static final String TABLE_PROVINSI = "provinsi";
 
    // Login Table Columns names
    private static final String KEY_ID = "IDPROVINSI";
    private static final String KEY_USERNAME = "NAMAPROVINSI";

    public DatabaseHandler(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }
 
    // Creating Tables
    @Override
    public void onCreate(SQLiteDatabase db) {
    	db.execSQL("DROP TABLE IF EXISTS " + TABLE_PROVINSI);
        String CREATE_TABLE_PROVINSI = "CREATE TABLE " + TABLE_PROVINSI + "("
                + KEY_ID + " INTEGER PRIMARY KEY,"
                + KEY_USERNAME + " TEXT"+")";
        db.execSQL(CREATE_TABLE_PROVINSI);
    }
 
    // Upgrading database
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // Drop older table if existed
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_PROVINSI);
 
        // Create tables again
        onCreate(db);
    }
 


    //Getting user data from database

    public List<String> getProvinsi(){
        List<String> list = new ArrayList<String>();
        String selectQuery = "SELECT  * FROM " + TABLE_PROVINSI;
          
        SQLiteDatabase db = this.getReadableDatabase();
        Cursor cursor = db.rawQuery(selectQuery, null);
        // Move to first row
        if(cursor.moveToFirst()){
        	do{
        		list.add(cursor.getString(1));
        	}
        	while (cursor.moveToNext());
        }
        cursor.close();
        db.close();
        // return user
        return list;
    }
 
}

